﻿using SuporeSliplampApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Supore.APP.UI;
using Supore.APP.UI.Controls.Notify;
using SuporeSliplampApp.Models;
using SuporeSliplampApp.Service;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// NewPatientWindow.xaml 的交互逻辑
    /// </summary>
    public partial class NewPatientWindow : Window
    {
        NewPatientViewModel viewModel;
        AddPatientService service;

        public NewPatientWindow()
        {
            InitializeComponent();
            viewModel = new NewPatientViewModel();
            service = new AddPatientService();
            DataContext = viewModel;
            //p_sex.ItemsSource = viewModel.cbbList;
        }
        
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void getInputData()
        {
            viewModel.Patient.Name = p_name.Text;
        }

        private void confirm_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(p_name.Text))
            {
                LayUINotify.ShowInfo("姓名不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(p_ID.Text))
            {
                LayUINotify.ShowInfo("病人ID不能为空！");
                return;
            }
            PatientModel model = new PatientModel();
            model.Name = p_name.Text;
            model.P_ID = p_ID.Text;
            ComboBoxItem cbi =(ComboBoxItem)p_sex.SelectedItem;
            model.SEX = cbi.Content.ToString();
            model.Birth = p_birth.SelectedDate.Value;
            model.Adreess = p_adress.Text;
            model.PhoneNum = p_phone.Text;
            model.Email = p_email.Text;
            model.Creator = App.Current.Properties["UserName"].ToString();
            if (!service.AddPatient(model))
            {
                LayUINotify.ShowInfo("保存失败！");
                return;
            }
            else
            {
                LayUINotify.ShowSuccess("保存成功！");
                
            }
            MainViewModel.GetInstance().patientModel.Name = model.Name;
            MainViewModel.GetInstance().patientModel.P_ID = model.P_ID;
            MainViewModel.GetInstance().patientModel.SEX = model.SEX;
            MainViewModel.GetInstance().patientModel.Str_Birth = model.Birth.ToShortDateString();
            MainViewModel.GetInstance().patientModel.Birth = model.Birth;
            MainViewModel.GetInstance().patientModel.Adreess = model.Adreess;
            MainViewModel.GetInstance().patientModel.PhoneNum = model.PhoneNum;
            MainViewModel.GetInstance().patientModel.Email = model.Email;
            MainViewModel.GetInstance().patientModel.Creator = model.Creator;
            this.Close();
            
        }

        private void submitData()
        {
            
        }

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Keyboard.ClearFocus();
            this.DragMove();
        }


    }
}
